use colored::*;
use whoami;
use std::env;

pub struct ShellPrompt {
	user: String,		// 用户名
	hostname: String,	// 主机名
	path: String,		// 当前工作路径
}

impl ShellPrompt {
	pub fn new() -> Self {
		Self { 
			user: whoami::username(), 
			hostname: whoami::devicename(), 
			path: env::current_dir().unwrap().display().to_string()
		}
	}

	pub fn set_user(&mut self, user: String) {
		self.user = user		
	}

	pub fn user(&self) -> &String {
		&self.user
	}

	pub fn set_hostname(&mut self, hostname: String) {
		self.hostname = hostname
	}

	pub fn hostname(&self) -> &String {
		&self.hostname
	}

	pub fn set_path(&mut self, path: String) {
		self.path = path
	}

	pub fn path(&self) -> &String {
		&self.path
	}

	pub fn prompt(&self) -> String {
		format!(
			"{}@{}:{}# ",
			self.user.green(),
			self.hostname.yellow(),
			self.path.blue()
		)
	}
}